var special_flag = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？ ]");
var prevent = false;

$(document).ready(function () {


});

$("#nickname").blur(function () {
    var showWrong = false;
    var wrongMsg;
    if ($(this).val() == null || $(this).val() == "" || $(this).val() == undefined) {
        showWrong = true;
        wrongMsg = "昵称不能为空！";
    } else if ($(this).val().match(/^[ ]*$/)) {
        showWrong = true;
        wrongMsg = "昵称不能包含空格！";
    } else if (special_flag.test($(this).val())) {
        showWrong = true;
        wrongMsg = "昵称不能包含特殊符号！";
    } else {
        showWrong = false
    }
    if (showWrong) {
        $(this).css("border-color", "#FF5722");
        $(".content .error_msg2").css('display', 'block');
        $(".content .error_msg2").text(wrongMsg);
        prevent = true;
    } else {
        prevent = false;
        $(".content .error_msg2").css('display', 'none');
        $(this).css("border-color", "#eee");
    }
})

$("#password").blur(function () {
    var showWrong = false;
    var wrongMsg;
    if ($(this).val() == null || $(this).val() == "" || $(this).val() == undefined) {
        showWrong = true;
        wrongMsg = "密码不能为空！";
    } else if ($(this).val().match(/^[ ]*$/)) {
        showWrong = true;
        wrongMsg = "密码不能包含空格！";
    } else if (special_flag.test($(this).val())) {
        showWrong = true;
        wrongMsg = "密码不能包含特殊符号！";
    } else {
        showWrong = false
    }
    if (showWrong) {
        prevent = true;
        $(this).css("border-color", "#FF5722");
        $(".content .error_msg2").css('display', 'block');
        $(".content .error_msg2").text(wrongMsg);
    } else {
        prevent = false;
        $(".content .error_msg2").css('display', 'none');
        $(this).css("border-color", "#eee");
    }
})

$("#telephone").blur(function () {
    var showWrong = false;
    if ($(this).val() == null || $(this).val() == "" || $(this).val() == undefined) {
        showWrong = true;
    } else if ($(this).val().match(/^[ ]*$/)) {
        showWrong = true;
    } else if (special_flag.test($(this).val())) {
        showWrong = true;
    } else if ($(this).val().length != 11) {
        showWrong = true;
    } else {
        showWrong = false
    }
    if (showWrong) {
        prevent = true;
        $(this).css("border-color", "#FF5722");
    } else {
        prevent = false;
        $(".input-check > button").attr("class", "qy-btn qy-btn-normal");
        $(this).css("border-color", "#eee");
    }
})

function toLogin() {
    $("#mainIframe", parent.document).attr("src", "toLogin");
};

$("#agree-btn").click(function () {
    if ($(this).is(':checked')) {
        $(".content-btn > button").attr("class", "qy-btn qy-btn-normal");
    } else {
        $(".content-btn > button").attr("class", "qy-btn qy-btn-disabled");
    }
});

function Signup() {

    var nickname = $("#nickname").val();
    var password = $("#password").val();
    var telephone = $("#telephone").val();

    var user = {
        nickname: nickname,
        password: password,
        telephone: telephone
    };

    if(prevent){
        ShowMsg("请正确输入！");
    }else {

    $.ajax({
        type: "post",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/loginLog/signup",
        data: user,
        success: function (result) {
            if (result.code == 200) {
                ShowMsg(result.msg);
                setTimeout("toLogin()",2000);
            } else {
                $(".content .error_msg2").css('display', 'block').show(300).delay(3000).hide(300);
                $(".content .error_msg2").text(result.msg);
            }
        },
        error: function () {
            ShowMsg("请重试！");
        }
    });

    }

};

